package com.noname.lib_base_java.glide;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.noname.lib_base_java.R;

/**
 * Author: Lmoumou
 * Date: 2018-12-11 12:21
 * 文件名: LoadImageUtils
 * 描述:
 */
public class LoadImageUtils {

    /**
     * @param url
     * @param imageView
     * @param resId
     */
    public static void loadImage(String url, ImageView imageView, int resId) {
        if (imageView == null) {
            return;
        }
        RequestOptions requestOptions = new RequestOptions()
                .placeholder(resId)
                .error(resId)
                .diskCacheStrategy(DiskCacheStrategy.ALL);
        Glide.with(imageView.getContext().getApplicationContext())
                .load(url)
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView);
    }

    /**
     * @param url
     * @param imageView
     */
    public static void loadImage(String url, ImageView imageView) {
        if (imageView == null) {
            return;
        }
        RequestOptions requestOptions = new RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.img_load)
                .error(R.drawable.img_load);

        Glide.with(imageView)
                .load(url)
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView);
    }

    /**
     * @param url
     * @param imageView
     */
    public static void loadImage(String url, ImageView imageView,RequestOptions requestOptions) {
        if (imageView == null) {
            return;
        }
        Glide.with(imageView)
                .load(url)
                .apply(requestOptions)
//                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView);
    }

    /**
     * 模糊
     *
     * @param url
     * @param imageView
     */
    public static void loadBlurImage(String url, ImageView imageView) {
        if (imageView == null) {
            return;
        }
        RequestOptions requestOptions = RequestOptions
                .bitmapTransform(new GlideBlurformation(imageView.getContext()))
                .placeholder(R.drawable.img_load)
                .error(R.drawable.img_load);

        Glide.with(imageView)
                .load(url)
                .apply(requestOptions)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView);
    }


}
